package thread;

import java.util.concurrent.Semaphore;

public class Demo32 {
    public static void main(String[] args) throws InterruptedException {
        Semaphore semaphore = new Semaphore(4);
        // 进行一次P操作
        semaphore.acquire();
        System.out.println("申请一次资源");
        semaphore.acquire();
        System.out.println("申请一次资源");
        semaphore.acquire();
        System.out.println("申请一次资源");
        semaphore.acquire();
        System.out.println("申请一次资源");

        // 进行一次V操作
        semaphore.release();
        System.out.println("释放一次资源");
    }
}
